import { getLanguage } from '@/locales/index'
import { cloneDeep } from 'lodash'
import { getLocalStorage } from '@/utils'
import {  getBookmarksList } from '@/api'
const setting = {
  state: {
    lang: getLanguage(), // 多语言
    isCollapse:  getLocalStorage('isCollapse'), // 菜单状态
    tabs: [], // 当前选中的值,
    enabledKeepAlive: true, // 页面开启缓存,
    activeFirstMenu: null, // 头部菜单选中
    activeFirstMenuName: null, //头部菜单选中名称
    subMenu: [], // 左侧菜单信息
    activeSideMenu: '', // 左侧和tab选中的标签值
    isShowView: true,
    currentLine: null,
    bookmarksList: [], //收藏夹
    sortingFinishedProductIn: 0, // 吊挂完成后进分拣开关
    configuration: null // 配置项
  },
  mutations: {
    updateState(state, payload) {
      Object.keys(payload).forEach((key) => {
        state[key] = cloneDeep(payload[key])
      });
    }
  },
  actions: {
    // 获取客户机列表
    getBookmarks ({ commit }) {
      return new Promise((reslove, reject) => {
        getBookmarksList( ).then(res => {
          if (!res.success) reject('error')
          commit('updateState', { bookmarksList: res.data })
          reslove()
        }).catch(err => {
          reject(err)
        })
      })
    },
  }
}
export default setting 